home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue29 / mrecsort / MRECSORT.ZIP / DemoUn.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-11-30  |  2.4 KB  |  93 lines

  1. {+--------------------------------------------------------------------------+
  2.  | Unit:   DemoUnit
  3.  | Created:     8.97
  4.  | Author:      Martin Waldenburg
  5.  | Copyright    1997, all rights reserved.
  6.  | Description: Demo for the FixRecSort engine.
  7.  | Version:     1.0
  8.  | Status       FreeWare
  9.  | It's provided as is, without a warranty of any kind.
  10.  | You use it at your own risc.
  11.  | E-Mail me at Martin.Waldenburg@t-online.de
  12.  +--------------------------------------------------------------------------+}
  13. unit DemoUn;
  14.  
  15. interface
  16.  
  17. uses
  18.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  19.   StdCtrls, mwFixedRecSort, mwFastTime;
  20.  
  21. type
  22.     PDemoData = ^TDemoData;
  23.     TDemoData = record
  24.                   Number: Integer;
  25.                   Data1: String[10];
  26.                   Data2: String[30];
  27.                 end;
  28.   TForm1 = class(TForm)
  29.     Button1: TButton;
  30.     OpenDialog1: TOpenDialog;
  31.     Label1: TLabel;
  32.     Button2: TButton;
  33.     Time1: TmwFastTime;
  34.     procedure FormCreate(Sender: TObject);
  35.     procedure FormDestroy(Sender: TObject);
  36.     procedure Button1Click(Sender: TObject);
  37.     procedure Button2Click(Sender: TObject);
  38.   private
  39.     FixRecSort: TFixRecSort;
  40.   public
  41.     { Public-Deklarationen }
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.   DemoData: PDemoData;
  47.   DData: TDemoData;
  48.  
  49. implementation
  50.  
  51. {$R *.DFM}
  52.  
  53. function Compare(Item1, Item2: Pointer): Integer;
  54. begin
  55.    Result:= CompareText(PDemoData(Item1)^.Data1, PDemoData(Item2)^.Data1);
  56.    { The comparision with the typecast is very comfortable but cost lots of time.
  57.      However, you will find this only noticeable when sorting Files that fit in
  58.      Memory, for large amounts of Records (Millions) windows file buffering system
  59.      will equalize this.
  60.      The faster way is do do a comparision from position one to position two.}
  61. end;
  62.  
  63. procedure TForm1.FormCreate(Sender: TObject);
  64. begin
  65.   FixRecSort:= TFixRecSort.Create(48);
  66. end;
  67.  
  68. procedure TForm1.FormDestroy(Sender: TObject);
  69. begin
  70.   FixRecSort.Free;
  71. end;
  72.  
  73. procedure TForm1.Button1Click(Sender: TObject);
  74. begin
  75.   if OpenDialog1.Execute then
  76.     begin
  77.       FixRecSort.Init(OpenDialog1.FileName);
  78.       FixRecSort.MaxLines:= 200000;
  79.       FixRecSort.MaxMem:= 4000000;
  80.       Time1.Start;
  81.       FixRecSort.Start(Compare);
  82.       Time1.Stop;
  83.       Label1.Caption:= Time1.ElapsedTime;
  84.     end;
  85. end;
  86.  
  87. procedure TForm1.Button2Click(Sender: TObject);
  88. begin
  89.   Close;
  90. end;
  91.  
  92. end.
  93.